package com.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.system.mapper.SysMenuMapper;
import com.system.mapper.SysStaffMapper;
import com.system.service.ISysMenuService;
import com.system.vo.SysMenuVO;

@Service("sysMenuService")
public class SysMenuServiceImpl implements ISysMenuService {
	
	@Autowired
	private SysStaffMapper sysMenuDao;
	
	@Autowired
	private SysMenuMapper menuMapper;
	
	@Override
	public List<SysMenuVO> findAllMenu() {
		return menuMapper.findAllMenu();
	}

	public void createMenu(List<SysMenuVO> sysMenuVOs) {
		menuMapper.createMenu(sysMenuVOs);
	}

    //根据ID删除Menu
	public void deleteMenuById(List<SysMenuVO>sysMenuVOs) {
		menuMapper.deleteMenuById(sysMenuVOs);
	}

	@Override
	public void updateMenus(List<SysMenuVO> sysMenuVOs) {
		menuMapper.updateMenus(sysMenuVOs);
	}

	@Override
	public List<SysMenuVO> findMenuByID(List<String>menu_ids) {
		
		
		return menuMapper.findNextSysMenuVOsByIds(menu_ids);
	}
	/**
	 * 循环查询所有菜单及其子菜单
	 * @param menu_ids
	 * @return
	 */
	public List<SysMenuVO> findAllChildrenMenu(List<String>menu_ids) {
		List<SysMenuVO> list=new ArrayList<SysMenuVO>();
		list = menuMapper.findMenusByMenuIds(menu_ids);
		List<SysMenuVO> children = menuMapper.findAllChildrenMenu(menu_ids);
		while(children.size()>0){
			list.addAll(children);
			menu_ids.clear();
			for (SysMenuVO sysMenuVO : children) {
				menu_ids.add(sysMenuVO.getMenuId());
			}
			children = menuMapper.findAllChildrenMenu(menu_ids);
		}
		return list;
		
	}
	@Override
	public void deleteRoleAndMenuByID(String menuId) {
		menuMapper.deleteRoleAndMenuByID(menuId);
	}

	@Override
	public List<SysMenuVO> findMenuSByMenuID(List<String> menuIds) {
		List <SysMenuVO> menulist = menuMapper.findMenusByMenuIds(menuIds);
		return menulist;
	}

	
}
